///******************** NG.Respate(C)  **********************************
//* 产品名称: Respate 科技
//* 文件名称: signal.c
//* 程序作者: 雷帕特公司(南宫子萍)
//* 程序版本: V1.1														   
//* 编制日期: 2019/1/29
//* 功能描述: 系统日志
//* QQ:	2085827949
//**********************************************************************/

#include <unistd.h>
#include <stdlib.h>
#include "stdlib.h"
#include "lap_lib.h"
#include "laperro.h"
#include <errno.h>

#if 0
#include "pthread.h"

pthread_mutex_t mutex1 = PTHREAD_MUTEX_INITIALIZER;    // 
pthread_mutex_t mutex2 = PTHREAD_MUTEX_INITIALIZER;

void *test_thread(void *dat)
{
    pthread_mutex_lock(&mutex2);
    pthread_mutex_trylock(&mutex1);
    printf(" get &mutex2\r\n");
    int ret;
    while (1){

        if((ret = pthread_mutex_trylock(&mutex1)) == 0)break;
        printf("1 ret :%d  [%s]\n", ret, strerror(ret));
        sleep(1);
    }
    printf("i get &mutex1\r\n");
    pthread_mutex_unlock(&mutex1);
    pthread_mutex_unlock(&mutex2);
    pthread_detach(pthread_self());
    return NULL;
}

static void Lap_trylock()
{
    pthread_t tid;
    // 初始化互斥锁
    // pthread_mutex_init(&mutex1);
    // pthread_mutex_init(&mutex2);
    
    
    perror("1  try");
    pthread_create(&tid, NULL, test_thread, NULL);
    sleep(1);
    while(1);
    pthread_mutex_lock(&mutex1);

    int ret;
    while (1)
    {
        sleep(1);

        if((ret = pthread_mutex_trylock(&mutex2)) == 0)break;
        printf("2 ret :%d  [%s]\n", ret, strerror(ret));
    }
     printf("i get mutex2r\n");  
    pthread_mutex_unlock(&mutex2); 

    pthread_mutex_destroy(&mutex2);
    pthread_mutex_destroy(&mutex1);
    

    printf("fuck off !\n");  

}

int main(void)
{
    LAP_ErrOutSet(NULL);  // 初始化 错误信息

    Lap_trylock();
    return 0;
}
#endif